<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
</head>
<body>
<div>
    <button onclick="testGet()">GET请求</button>
    <button onclick="testPost()">POST请求</button>
    <button onclick="testPut()">PUT请求</button>
    <button onclick="testDelete()">DELETE请求</button>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.js"></script>
<script>
    function testGet() {
        // axios.get('http://localhost:3000/posts')
        // axios.get('http://localhost:3000/posts/1')
        axios.get('http://localhost:3000/posts?id=1')
        .then(response=>{
            console.log('/get',response.data)
        })
    }
    function testPost() {
        axios.post('http://localhost:3000/posts', {
            "title": "json-server3",
            "author": "typicode3"
        }).then(response=>{
                console.log('/post',response.data)
            })
    }
    function testPut() {
        axios.put('http://localhost:3000/posts/3',
            {
                "title": "json-server3...",
                "author": "typicode3..."
            })
            .then(response=>{
                console.log('/put',response.data)
            })
    }
    function testDelete() {
        axios.delete('http://localhost:3000/posts/3')
            .then(response=>{
                console.log('/delete',response.data)
            })
    }
</script>
</body>
</html>
